package com.cskaoyan.shopping.controller;

import com.cskaoyan.mall.commons.result.ResponseData;
import com.cskaoyan.mall.commons.result.ResponseUtil;
import com.cskaoyan.mall.constant.ShoppingRetCode;
import com.cskaoyan.shopping.dal.persistence.PanelContentMapper;
import com.cskaoyan.shopping.dto.*;
import com.cskaoyan.shopping.service.IProductPanelGoodsService;
import javafx.scene.layout.Pane;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author FuHao
 * @version 1.0.0
 * @description TODO 完成主页显示，导航栏显示及列举所有商品种类
 * @date 2022/6/17 20:06
 */

@RestController
public class ProductPanelGoodsController {

    @Autowired
    IProductPanelGoodsService iProductPanelGoodsService;

    /**
     * 显示商城主页面
     * @return
     * @author FuHao
     * @since 2022/06/19 13:04
     */
    @GetMapping("/shopping/homepage")
    public ResponseData showHomePage() {

        // PanelDtoResponse panelDtos = new PanelDtoResponse();
        // 调用Service请求
        HomePageResponse homePageResponse = iProductPanelGoodsService.IProductPanelHomepage();


        if (ShoppingRetCode.SUCCESS.getCode().equals(homePageResponse.getCode())) {
            // 执行成功，直接返回前端需要的数据
            // return new ResponseUtil().setData(homePageResponse.getPanelContentItemDtos());
            ResponseData responseData = new ResponseUtil().setData(homePageResponse.getPanelContentItemDtos());
            System.out.println("niu");
            // ResponseData<Object> responseData = new ResponseData<>();
            return responseData;
        }
        // 执行失败
        return new ResponseUtil().setErrorMsg(homePageResponse.getMsg());

    }


    /**
     * 显示导航栏
     * @return
     * @author FuHao
     * @since 2022/06/19 12:22
     */
    @GetMapping("shopping/navigation")
    public ResponseData showNavigation() {

        NavListResponse navigation = iProductPanelGoodsService.showNavigation();

        if (ShoppingRetCode.SUCCESS.getCode().equals(navigation.getCode())) {
            // 执行成功，直接返回前端需要的数据
            return new ResponseUtil().setData(navigation.getPannelContentDtos());
        }
        // 调用失败
        return  new ResponseUtil().setErrorMsg(navigation.getMsg());

    }


    /**
     * 实现目录的显示 categories
     * @return
     * @author FuHao
     * @since 2022/06/19 12:43
     */

    @GetMapping("shopping/categories")
    public ResponseData showCategories() {

        CategoriesResponse categoriesResponse = iProductPanelGoodsService.showCategories();

        if (ShoppingRetCode.SUCCESS.getCode().equals(categoriesResponse.getCode())) {
            // 执行成功，直接返回前端需要的数据
            return new ResponseUtil().setData(categoriesResponse.getProductCateDtoList());
        }
        // 调用失败
        return  new ResponseUtil().setErrorMsg(categoriesResponse.getMsg());

        // return categoriesResponse;

    }

}
